package com.ruoyi.web.controller.business;

import java.util.List;

import com.ruoyi.system.domain.Shangjiatype;
import com.ruoyi.system.service.IShangjiatypeService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.enums.BusinessType;

import com.ruoyi.framework.web.base.BaseController;
import com.ruoyi.common.page.TableDataInfo;
import com.ruoyi.common.base.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;

/**
 * 商家类型 信息操作处理
 * 
 * @author ruoyi
 * @date 2019-07-16
 */
@Controller
@RequestMapping("/system/shangjiatype")
public class ShangjiatypeController extends BaseController
{
    private String prefix = "system/shangjiatype";
	
	@Autowired
	private IShangjiatypeService shangjiatypeService;
	
	@RequiresPermissions("system:shangjiatype:view")
	@GetMapping()
	public String businesstype()
	{
	    return prefix + "/shangjiatype";
	}
	
	/**
	 * 查询商家类型列表
	 */
	@RequiresPermissions("system:shangjiatype:list")
	@PostMapping("/list")
	@ResponseBody
	public TableDataInfo list(Shangjiatype businesstype)
	{
		startPage();
        List<Shangjiatype> list = shangjiatypeService.selectBusinesstypeList(businesstype);
		return getDataTable(list);
	}
	
	
	/**
	 * 导出商家类型列表
	 */
	@RequiresPermissions("system:shangjiatype:export")
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(Shangjiatype businesstype)
    {
    	List<Shangjiatype> list = shangjiatypeService.selectBusinesstypeList(businesstype);
        ExcelUtil<Shangjiatype> util = new ExcelUtil<Shangjiatype>(Shangjiatype.class);
        return util.exportExcel(list, "shangjiatype");
    }
	
	/**
	 * 新增商家类型
	 */
	@GetMapping("/add")
	public String add()
	{
	    return prefix + "/add";
	}
	
	/**
	 * 新增保存商家类型
	 */
	@RequiresPermissions("system:shangjiatype:add")
	@Log(title = "商家类型", businessType = BusinessType.INSERT)
	@PostMapping("/add")
	@ResponseBody
	public AjaxResult addSave(Shangjiatype businesstype)
	{		
		return toAjax(shangjiatypeService.insertBusinesstype(businesstype));
	}

	/**
	 * 修改商家类型
	 */
	@GetMapping("/edit/{shangjiatypeId}")
	public String edit(@PathVariable("shangjiatypeId") Integer businesstypeId, ModelMap mmap)
	{
		Shangjiatype businesstype = shangjiatypeService.selectBusinesstypeById(businesstypeId);
		mmap.put("shangjiatype", businesstype);
	    return prefix + "/edit";
	}
	
	/**
	 * 修改保存商家类型
	 */
	@RequiresPermissions("system:shangjiatype:edit")
	@Log(title = "商家类型", businessType = BusinessType.UPDATE)
	@PostMapping("/edit")
	@ResponseBody
	public AjaxResult editSave(Shangjiatype businesstype)
	{		
		return toAjax(shangjiatypeService.updateBusinesstype(businesstype));
	}
	
	/**
	 * 删除商家类型
	 */
	@RequiresPermissions("system:shangjiatype:remove")
	@Log(title = "商家类型", businessType = BusinessType.DELETE)
	@PostMapping( "/remove")
	@ResponseBody
	public AjaxResult remove(String ids)
	{		
		return toAjax(shangjiatypeService.deleteBusinesstypeByIds(ids));
	}
	
}
